/*
 * @Author: 王雁鹏
 * @Date: 2023-06-08 10:05:20
 * @LastEditTime: 2023-07-03 20:08:57
 * @LastEditors: Please set LastEditors
 * @Description: 
 * @FilePath: \expressf:\web-vue\bs-nodejs-background-code\routes\address\service.js
 * ------------------
 */
const request = require('request');
var req = require("../../utils/router");
const db = require("../../mysql/index.js");
const config = require("./config.js");
const { generateUUID } = require("../../utils/func.js")
let { router, GetRouter, PostRouter } = req
// 设置地址
new PostRouter().send('/setAddress', function (res, data) {
    let { id, openid, link, type, address, remark, area, name, isdef } = data
    let condition = {
        openid, link, type, address, remark, area, name, isdef
    }
    if (isdef == "1") {
        db.setData({
            ...config,
            query: `openid='${openid}'`,
            condition: { isdef: "0" }
        }, () => {
            db.setData({
                ...config,
                id,
                condition
            }, (rows, fields) => {
                res.send({ code: 200, data: rows });
            })
        })
    } else {
        db.setData({
            ...config,
            id,
            condition
        }, (rows, fields) => {
            res.send({ code: 200, data: rows });
        })
    }
})
// 获取地址
new GetRouter().send('/getAddress', (res, data) => {
    let { openid } = data
    let obj = {
        openid: db.LIKE({ ...config, select: { openid } }),
    }
    let select = db.Params(obj)
    db.select({
        ...config,
        select,
    }, (rows) => {
        res.send({ code: 200, data: rows });
    })
})
// 删除地址
new GetRouter().send('/delAddress', (res, data) => {
    let { id } = data
    let obj = { id: db.EQ({ ...config, select: { id } }) }
    let select = db.Params(obj)
    db.delete({
        ...config,
        select,
    }, (rows) => {
        res.send({ code: 200, data: rows });
    })
})
module.exports = router